﻿Imports System.Data.OracleClient
Public Class UserListForm
    '一覧の新規表示
    Private Sub ListForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            'データ一覧表示
            Me.M_USERTableAdapter.Fill(Me.DataSetUserTbl.M_USER)
            Me.gridView.RowHeadersVisible = False
            '結果が0件の場合
            If Me.DataSetUserTbl.M_USER.Rows.Count = 0 Then
                MessageCommon.showInformation(My.Resources.I_DATA_ZERO)
            End If
        Catch ex As Exception
            MessageCommon.showError(My.Resources.E_SYSTEM_FAIL)
        End Try
    End Sub
    '新規追加ボタン処理
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Try
            Dim inputForm = New UserInputForm
            'データ取得
            inputForm.userInfo.dispFlg = "I"
            '表示及び親画面を非活性にする
            inputForm.ShowDialog()
            '一覧データの再表示
            Me.M_USERTableAdapter.Fill(Me.DataSetUserTbl.M_USER)
        Catch ex As Exception
            MessageCommon.showError(My.Resources.E_SYSTEM_FAIL)
        End Try
    End Sub
    '共通処理
    Private Sub doOperation(ByVal userID As String, ByVal dispFlg As String)
        Try
            Dim inputForm = New UserInputForm
            inputForm.userInfo.dispFlg = dispFlg
            Dim dac = New M_UserDao
            Dim data = dac.getUserInfo(userID)
            inputForm.userInfo.userID = data.Rows(0)(0).ToString
            inputForm.userInfo.password = data.Rows(0)(1).ToString
            inputForm.userInfo.repassword = data.Rows(0)(1).ToString
            inputForm.userInfo.userName = data.Rows(0)(2).ToString
            inputForm.userInfo.userType = data.Rows(0)(3).ToString
            '表示及び親画面を非活性にする
            inputForm.ShowDialog()
            Me.M_USERTableAdapter.Fill(Me.DataSetUserTbl.M_USER)
        Catch ex As Exception
            MessageCommon.showError(My.Resources.E_SYSTEM_FAIL)
        End Try
    End Sub
    '更新、削除ボタンの処理
    Private Sub gridView_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gridView.CellContentClick
        Try
            If e.RowIndex < 0 Then
                Exit Sub
            End If
            Dim dispFlg = ""
            If e.ColumnIndex = gridView.Columns.Count - 2 Then
                dispFlg = "U"
            ElseIf e.ColumnIndex = gridView.Columns.Count - 1 Then
                dispFlg = "D"
            Else
                Exit Sub
            End If
            doOperation(gridView.Rows(e.RowIndex).Cells(0).Value.ToString, dispFlg)
        Catch ex As Exception
            MessageCommon.showError(My.Resources.E_SYSTEM_FAIL)
        End Try
    End Sub
    'CSV出力ボタンの処理
    Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
        Try
            If csvSaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
                If (New CSVDao).exportM_USER(csvSaveFileDialog.FileName) = True Then
                    MessageCommon.showInformation(MessageCommon.getMessage("CSV出力", My.Resources.E_ACTION_SUCCEEDED))
                Else
                    MessageCommon.showError(MessageCommon.getMessage("CSV出力", My.Resources.E_ACTION_FAILED))
                End If
            End If
        Catch ex As Exception
            MessageCommon.showError(My.Resources.E_SYSTEM_FAIL)
        End Try
    End Sub
    'CSV取込ボタンの処理
    Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click
        Try
            Dim csvImpForm = New CSVImportForm
            csvImpForm.ShowDialog()
            Me.M_USERTableAdapter.Fill(Me.DataSetUserTbl.M_USER)
        Catch ex As Exception
            MessageCommon.showError(My.Resources.E_SYSTEM_FAIL)
        End Try
    End Sub
    '閉じるボタン処理
    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Try
            If MessageCommon.showConfirm(My.Resources.C_SYSTEM_EXIT) = Windows.Forms.DialogResult.OK Then
                Me.Close()
            End If
        Catch ex As Exception
            MessageCommon.showError(My.Resources.E_SYSTEM_FAIL)
        End Try
    End Sub

    Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.Click
        Try
            Me.M_USERTableAdapter.Fill(Me.DataSetUserTbl.M_USER)
        Catch ex As Exception
            MessageCommon.showError(My.Resources.E_SYSTEM_FAIL)
        End Try
    End Sub
End Class